Fix css parser tests
authorMatthias Clasen <mclasen@redhat.com>
Tue, 16 Oct 2012 10:00:40 +0000 (06:00 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 16 Oct 2012 10:02:03 +0000 (06:02 -0400)
Parsing a shorthand background property was running into unexpected
errors when trying position values where there were none. To fix this,
introduce a try_parse variant of the position parse function that
silently returns NULL.

gtk/gtkcsspositionvalue.c
gtk/gtkcsspositionvalueprivate.h
gtk/gtkcssshorthandpropertyimpl.c

index 09c845d2fc07e5c26f8ec401ba7bead57a117c1a..8f09db72f2517cb11675c62614b45e2443330bcb 100644 (file)
@@ -173,8 +173,8 @@ _gtk_css_position_value_new (GtkCssValue *x,
   return result;
 }
 
-GtkCssValue *
-_gtk_css_position_value_parse (GtkCssParser *parser)
+static GtkCssValue *
+position_value_parse (GtkCssParser *parser, gboolean try)
 {
   static const struct {
     const char *name;
@@ -225,7 +225,8 @@ _gtk_css_position_value_parse (GtkCssParser *parser)
         }
       else
         {
-          _gtk_css_parser_error (parser, "Unrecognized position value");
+          if (!try)
+            _gtk_css_parser_error (parser, "Unrecognized position value");
           return NULL;
         }
     }
@@ -245,7 +246,8 @@ _gtk_css_position_value_parse (GtkCssParser *parser)
         {
           if (missing != &y)
             {
-              _gtk_css_parser_error (parser, "Invalid combination of values");
+              if (!try)
+                _gtk_css_parser_error (parser, "Invalid combination of values");
               _gtk_css_value_unref (y);
               return NULL;
             }
@@ -269,7 +271,8 @@ _gtk_css_position_value_parse (GtkCssParser *parser)
       if ((names[first].horizontal && !names[second].vertical) ||
           (!names[first].horizontal && !names[second].horizontal))
         {
-          _gtk_css_parser_error (parser, "Invalid combination of values");
+          if (!try)
+            _gtk_css_parser_error (parser, "Invalid combination of values");
           _gtk_css_value_unref (x);
           _gtk_css_value_unref (y);
           return NULL;
@@ -279,6 +282,18 @@ _gtk_css_position_value_parse (GtkCssParser *parser)
   return _gtk_css_position_value_new (x, y);
 }
 
+GtkCssValue *
+_gtk_css_position_value_parse (GtkCssParser *parser)
+{
+  return position_value_parse (parser, FALSE);
+}
+
+GtkCssValue *
+_gtk_css_position_value_try_parse (GtkCssParser *parser)
+{
+  return position_value_parse (parser, TRUE);
+}
+
 double
 _gtk_css_position_value_get_x (const GtkCssValue *position,
                                double             one_hundred_percent)
index ee3b1521cd0c47f5cb6a73ab9761988a1e69f90f..d1d113bb13b8afcfd4e7f79c6d1643ae94a7ae47 100644 (file)
@@ -26,8 +26,9 @@
 G_BEGIN_DECLS
 
 GtkCssValue *   _gtk_css_position_value_new           (GtkCssValue            *x,
-                                                     GtkCssValue            *y);
+                                                       GtkCssValue            *y);
 GtkCssValue *   _gtk_css_position_value_parse         (GtkCssParser           *parser);
+GtkCssValue *   _gtk_css_position_value_try_parse     (GtkCssParser           *parser);
 
 double          _gtk_css_position_value_get_x         (const GtkCssValue      *position,
                                                      double                  one_hundred_percent);
index 7dd3e3d1f2dfa2852d9dd18293e3c6a1b26be754..0e9524d2eaaece95b82019369f8350d1590f86d0 100644 (file)
@@ -484,7 +484,7 @@ parse_one_background (GtkCssShorthandProperty  *shorthand,
           values[0] = _gtk_css_image_value_new (image);
         }
       else if (values[1] == NULL &&
-               (value = _gtk_css_position_value_parse (parser)))
+               (value = _gtk_css_position_value_try_parse (parser)))
         {
           values[1] = value;
           value = NULL;